package com.rem.flink.flink4Sink;


import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.connector.base.DeliveryGuarantee;
import org.apache.flink.connector.kafka.sink.KafkaRecordSerializationSchema;
import org.apache.flink.connector.kafka.sink.KafkaSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;


/**
 * sink kafka
 *
 * @author Rem
 * @date 2022/10/11
 */
public class SinkToKafkaTest {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<String> stream = env.readTextFile("input/clicks.csv");
        KafkaSink<String> sink = KafkaSink.<String>builder()
                .setBootstrapServers("10.224.18.157:9092,10.224.18.158:9092,10.224.18.159:9092")
                .setRecordSerializer(KafkaRecordSerializationSchema.builder()
                        .setTopic("clicks")
                        .setValueSerializationSchema(new SimpleStringSchema())
                        .build()
                )
                .setDeliverGuarantee(DeliveryGuarantee.AT_LEAST_ONCE)
                .build();

        stream.sinkTo(sink);

        env.execute();
    }
}

